package work;

import com.rabbitmq.client.*;
import util.ConncetionUtil;

import java.io.IOException;

public class Consumer2 {
    private static final String QUEUENAME="zfz";

    public static void main(String[] args) throws  Exception{
        Connection connection = ConncetionUtil.getConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare(QUEUENAME,false,false,false,null);
        channel.basicQos(1);
        channel.basicConsume(QUEUENAME,false,new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.err.println("复制体接收到的数据是："+new String(body));
                try {
                    Thread.sleep(300);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                channel.basicAck(envelope.getDeliveryTag(),false);
            }
        });

    }
}
